package cn.lutu.domain.repository.impl;

import cn.lutu.domain.repository.InvoiceRepository;
import cn.lutu.dao.mapper.InvoiceMapper;
import cn.lutu.protocol.entity.Invoice;
import cn.lutu.protocol.vo.InvoiceVO;
import cn.lutu.protocol.vo.adminVO.AdminInvoiceVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class InvoiceRepositoryImpl implements InvoiceRepository {
    @Autowired
    InvoiceMapper invoiceMapper;

    @Override
    public int insert(Invoice invoice) {
        log.debug("开始执行插入发票信息，参数为{}", invoice);
        return invoiceMapper.insert(invoice);
    }

    @Override
    public int deleteByOrderId(Long orderId) {
        log.debug("开始执行删除发票信息，参数为{}", orderId);
        QueryWrapper<Invoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_id", orderId);
        return invoiceMapper.delete(queryWrapper);
    }

    @Override
    public void updateById(Invoice invoice) {
        log.debug("开始执行修改发票信息，参数为{}",invoice);
        QueryWrapper<Invoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", invoice.getId());
        invoiceMapper.update(invoice, queryWrapper);
    }

    @Override
    public InvoiceVO selectByOrderId(Long orderId) {
        log.debug("开始执行查看发票信息，参数为{}", orderId);
        return invoiceMapper.selectByOrderId(orderId);
    }

    @Override
    public List<InvoiceVO> selectByUserId(Long userId) {
        log.debug("开始执行查看用户所有发票信息，参数为{}", userId);
        return invoiceMapper.selectByUserId(userId);
    }

    @Override
    public List<InvoiceVO> selectByKeyword(String keyword,Long userId) {
        log.debug("开始执行搜索发票信息，参数为{}", keyword);
        return invoiceMapper.selectByKeyword(keyword,userId);
    }

    @Override
    public List<AdminInvoiceVO> selectAll() {
        log.debug("开始执行查看所有发票信息");
        return invoiceMapper.selectAll();
    }


}
